package xmla

import (
	"crypto/md5"
	"encoding/hex"
	"time"

	"github.com/patrickmn/go-cache"
)

var c *cache.Cache

func init() {
	c = cache.New(5*time.Minute, 1*time.Minute)
}
func addCache(mdx string, cdata *CubeData) {
	h := md5.New()
	h.Write([]byte(mdx))
	cipherStr := h.Sum(nil)
	c.Add(hex.EncodeToString(cipherStr), cdata, 4*time.Hour)
}
func getCache(mdx string) (*CubeData, bool) {
	h := md5.New()
	h.Write([]byte(mdx))
	cipherStr := h.Sum(nil)
	data, found := c.Get(hex.EncodeToString(cipherStr))
	if found {
		return data.(*CubeData), true
	}
	return nil, false
}
